﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using PARCS.Core.Contracts;

namespace PARCS.Core
{
    public class EventTrace : IRecovery
    {
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //info.AddValue();
        }

        public void BeginTaskEvent(int taskNumber)
        {
            Console.Out.WriteLine("Trace: BeginTaskEvent, task number = " + taskNumber);
        }

        public void EndTaskEvent()
        {
            Console.Out.WriteLine("Trace: EndTaskEvent");
        }

        public int CreatePointEvent(PARCS.HostsServer.XHostInfo target, int pointNumber,
                                                                 int parentNumber)
        {
            Console.Out.WriteLine("Trace: CreatePointEvent, target = "
                                                 + target.name + ", pointNumber = "
                                                 + pointNumber + ", parentNumber = "
                                                 + parentNumber);
            return pointNumber;
        }

        public void DeletePointEvent(int pointNumber)
        {
            Console.Out.WriteLine("Trace: DeletePointEvent, pointNumber = " + pointNumber);
        }

        public IAlgorithmicModule ExecuteClassEvent(int pointNumber, String className)
        {
            Console.Out.WriteLine("Trace: ExecuteClassEvent, pointNumber = "
                                                 + pointNumber + ", className = "
                                                 + className);
            return null;
        }

        public void CreateChildEvent(int parent, int child)
        {
            Console.Out.WriteLine("Trace: CreateChildEvent, parent = "
                                                 + parent + ", child = "
                                                 + child);
        }

        public void CreateChannelEvent(int from, int to)
        {
            Console.Out.WriteLine("Trace: CreateChannelEvent, from = "
                                                 + from + ", to = "
                                                 + to);
        }

        public void AddUserDataEvent(int pointNumber, Object key, Object value)
        {
            Console.Out.WriteLine("Trace: AddUserDataEvent, pointNumber = " + pointNumber);
        }


        public void Write(int from, int index, Types type, object value)
        {
            Console.Out.WriteLine("Trace: Write, from = "
                                              + from + ", index = "
                                              + index + ", type = ");
            switch (type)
            {
                case Types.Byte:
                    Console.Out.WriteLine("Types.Byte, value = " + value);
                    break;
                case Types.Double:
                    Console.Out.WriteLine("Types.Double, value = " + value);
                    break;
                case Types.Int:
                    Console.Out.WriteLine("Types.Int, value = " + value);
                    break;
                case Types.Long:
                    Console.Out.WriteLine("Types.Long, value = " + value);
                    break;
                case Types.Object:
                    Console.Out.WriteLine("Types.Object");
                    break;
                case Types.Array:
                    Console.Out.WriteLine("Types.Array, value:");
                    foreach (var obj in (object[])value)
                    {
                        Console.Out.WriteLine(obj);
                    }
                    break;
                default:
                    Console.Error.WriteLine("Error: Recover internal error, inconsistent type");
                    break;
            }
        }

        public void Write(int from, int index, byte[] value)
        {
            Console.Out.WriteLine("Trace: Write, from = "
                                             + from + ", index = "
                                             + index + ", type = Types.Array");
        }
    }
}
